<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <title></title>
    <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="stylesheet" href="../css/mui.min.css">
    <link rel="stylesheet" type="text/css" href="../css/goods/address_list.css" />
    <link rel="stylesheet" href="../css/mui.picker.min.css">
    <script type="text/javascript">
        (function () {
            var clientWidth = document.documentElement ? document.documentElement.clientWidth : document.body.clientWidth;
            clientWidth = clientWidth || localStorage.getItem("clientWidth")
            if (clientWidth > 750)
                clientWidth = 750;
            document.documentElement.style.fontSize = clientWidth * 1 / 16 + "px";
        })();
    </script>
    <style>
        html,
        body,
        .mui-content {
            background-color: #ffffff;
        }

        .ptsp_top_stats {
            height: 20px;
            width: 100%;
            background-color: #ffffff;
            position: fixed;
            top: 0;
            left: 0;
            z-index: 10000;
        }

        .mui-action-back {
            height: 44px;
            width: 44px;
        }

        .mui-action-back img {
            width: 100%;
        }



        .mui-content {
            padding-bottom: 100px;
            padding-top: 44px !important;
        }

        .arr_left {
            background-image: url(../images/ptsp/left_arr_03.png);
            background-size: 24px 24px;
            background-position: center;
            background-repeat: no-repeat;
        }

        .mui-title {
            font-size: 0.768rem;
        }

        .mui-bar-nav a {
            font-size: 0.5973rem;
            color: #888888;
            line-height: 44px;
        }

        .address_list .address_item .btns .edit a {
            color: #353535;
        }
    </style>
</head>

<body>

    <header class="mui-bar mui-bar-nav" style="border-bottom: 1px solid #c5c5c5">
        <a class="mui-action-back mui-icon  mui-pull-left arr_left">
        </a>
        <h1 class="mui-title">收货地址</h1>
        <a class="mui-pull-right  right_icon" onclick="vue.add()" >
            <img src="../images/address_03.png">
        </a>
    </header>
    <div class="mui-content">
        <div>
            <div class="address_list" v-for="(item,i) in address_lists">
                <div class="address_item">
                    <div class="title">
                        <span class="name" v-html="item.name">{{item.name}}</span>
                        <span class="phone" v-html="item.phone">{{item.phone}}</span>
                    </div>
                    <div class="text">{{item.province}}{{item.city}}{{item.area}}{{item.address}}</div>
                    <div class="btns">
                        <span :class="item.default?'is_default default_active fl':'is_default fl'" @click="set_default(i)">
                            <i class="fl"></i>
                            <span class="fl">默认地址</span>
                        </span>
                        <span class="del fr" @click="del(i)">
                            <i class="fl"></i>
                            <span class="fl">删除</span>

                        </span>
                        <span class="edit fr" @click="edit(i)">
                            <a>
                                <!--<a href="my_adsbj.html">-->
                                <i class="fl"></i>
                                <span class="fl">编辑</span>
                            </a>
                        </span>

                    </div>
                </div>
                <div class="hr_20"></div>
            </div>


        </div>
    </div>
    <script src="../js/mui.min.js"></script>
    <script src="../js/vue.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="../js/js.js" type="text/javascript" charset="utf-8"></script>
    <script src="../js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="../js/host.config.js"></script>
    <script src="../js/tools/util.js" type="text/javascript" charset="utf-8"></script>
    <script>
        var vue = new Vue({
            el: ".mui-content",
            data: {
            	user:'',
                address_lists: [],
            },
            methods: {
                get_data: function (url, cb) {
                    mui.ajax(host_config.host + url, {
                        dataType: 'json',//服务器返回json格式数据
                        type: 'get',//HTTP请求类型
                        timeout: 10000,//超时时间设置为10秒；
                        // headers: { 'Content-Type': 'application/json' },
                        success: function (res) {
                            //服务器返回响应，根据响应结果，分析是否登录成功；
                            console.log(res);
                            if (res.code == 200) {
                                cb(res)
                            }
                        },
                        error: function (xhr, type, errorThrown) {
                            //异常处理；
                            console.log(type);
                        }
                    });
                },
                set_default: function (index) {
                    var d = this.address_lists;
                    
                    // uid 为用户ID 当前写死  uaid 为当前地址的ID
                    for (var i = 0; i < d.length; i++) {
                        if (i == index) {
                            d[i].default = 1;
                            mui.get(host_config.app_server+"address/defaultsite", {uid:this.user.uid, uaid: d[i].uaid }, function (data) {
                                console.log(data)
                                if (data == 1) {
                                	 mui.toast("设置成功")
//                                  mui.openWindow({
//                                      url: 'my.html',
//                                      id: 'my',
//                                  })
                                } else {
                                    mui.toast("网络失败,稍后重试")
                                }
                            })

                        } else {
                            d[i].default = 0;
                        }
                    }

                },
                edit: function (i) {
                    
                    localStorage.setItem("edit_address_info",JSON.stringify(this.address_lists[i]))
                    mui.openWindow({
                        url: 'my_adsbj.html',
                        id: 'my_adsbj',
                    })
                },
                del: function (e) {
                    console.log(vue.address_lists[e].uaid)
                    uaid = vue.address_lists[e].uaid
                    
                    mui.post(host_config.app_server+  "address/deladdress", { uaid: uaid }, function (data) {
                        console.log("data-->"+data)
                        if (data == 1) {
                            vue.address_lists.splice(e, 1)
                            mui.toast("删除成功")
                        }
                    })
                    
                },
                add: function () {
                    mui.openWindow("my_newads.html","my_newads.html")
                }
            },
            created:function(){
            	var user =  get_user_info();
            	if(user){
            		this.user = user
            	}else{
            		mui.toast("未登录");mui.openWindow("logn.html","logn.html")
            	}
            },
            mounted: function () {
                var that = this;
                var user = JSON.parse(localStorage.getItem("user"));
                if(user){
                	this.user = user;
                }else{
                	mui.toast("未登录");
                	mui.openWindow("logn.html","logn.html")
                }
               	
                console.log("url-->"+host_config.app_server+"address/addressList");
                console.log("uid-->"+that.user.uid)
                $.ajax({
                	url:host_config.app_server+"address/addressList",
                	type:'get',
                	data:{
                		uid : that.user.uid,
                	},
                	success:function(res){

                		res = JSON.parse(res)
                		console.log(res)
                  		that.address_lists = res.data
                	},
                	error:function(err){
                		console.log(err)
                	}
                })
//              mui.get(host_config.app_server+"address/addressList", { uid: user.uid }, function (data) {
//                  console.log(data);
//                  console.log(JSON.stringify(data))
//                  that.address_lists = data.data
//              }, 'json')
            }
        })


    </script>



</body>

</html>